package top.humbleyuan.dfs;

import top.humbleyuan.datastructure.tree.TreeNode;

/**
 * @Author HumbleYuan
 * @Date 2020/5/19 19:16
 * @Des 验证是否是相同的树
 */
public class LeetCode_100 {
    public static void main(String[] args) {
        TreeNode head1 = new TreeNode(2);
        head1.formTree();

        TreeNode head2 = new TreeNode(2);
        head2.formTree();

        System.out.println(isSameTree(head1, head2));
    }

    public static boolean isSameTree(TreeNode p, TreeNode q) {
        if(p == null && q == null) {
            return true;
        }

        if(p == null || q == null) {
            return false;
        }

        if(p.val != q.val) {
            return false;
        }

        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}
